﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Sprout.Repository
{
    /// <summary>
    /// 用于控制全局事务
    /// </summary>
    public class Transaction : IDisposable
    {
        bool waitExecute = false;
        public Transaction()
        {
            waitExecute = true;
            TransactionService.Instance.BeginTransaction();
        }

        /// <summary>
        /// 完成，即提交事务
        /// </summary>
        public void Complete()
        {
            TransactionService.Instance.Commit();
            waitExecute = false;
        }
        /// <summary>
        /// 释放
        /// </summary>
        public void Dispose()
        {
            if (waitExecute)
            {
                TransactionService.Instance.Rollback();
            }
        }
    }
}
